﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace QLTV.Forms.KeHoach
{
    public partial class frmBanCamKet : BaseForm
    {
        public frmBanCamKet()
        {
            InitializeComponent();
        }
        public int planid { get; set; }
        private void frmBanCamKet_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dsShortPlan.tblCrew' table. You can move, or remove it, as needed.
            this.tadCrew.Fill(this.dsShortPlan.tblCrew);
            // TODO: This line of code loads data into the 'dsShortPlan.tblShortPlan' table. You can move, or remove it, as needed.
            this.tblShortPlanTableAdapter.FillDSDuKienLen(this.dsShortPlan.tblShortPlan, planid);


        }

        private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            string crewID = viewDSTV.GetFocusedRowCellValue(colnCrewIDNext).ToString();
            xemCamKet(crewID);

        }
        private void xemCamKet(string crewID)
        {

            Database.dsShortPlan.tblCrewDataTable dtCrew = new Database.dsShortPlan.tblCrewDataTable();
            //string crewID = viewDSTV.GetFocusedRowCellValue(colnCrewIDNext).ToString();
             dtCrew = tadCrew.GetDataBy(crewID);
            Ultilities.preActive(@"{0}\Reports\bancamket.doc");
            string tenThuyenvien = viewDSTV.GetFocusedRowCellDisplayText(colnCrewIDNext);
      
            string diachi=dtCrew.Rows[0]["DiaChi"].ToString();
            string ngaySinh = ((DateTime)dtCrew.Rows[0]["dDateOfBirth"]).ToString("dd-MM-yyyy");
            string noiSinh = dtCrew.Rows[0]["cPlaceOfBirth"].ToString();
            string chucDanh = viewDSTV.GetFocusedRowCellDisplayText(colChucDanh);
            string soCMT = dtCrew.Rows[0]["cCMT"].ToString();
            string SDT = dtCrew.Rows[0]["cHandNo"].ToString();
            string date = String.Format("Hải Phòng, ngày {0} tháng {1} năm {2}", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year);

            Ultilities.replaceWord("<%CrewName%>", tenThuyenvien.ToUpper(),Ultilities.doc);
            Ultilities.replaceWord("<%BirthDate%>", ngaySinh, Ultilities.doc);
            Ultilities.replaceWord("<%CMT%>", soCMT, Ultilities.doc);
            Ultilities.replaceWord("<%Address%>", diachi, Ultilities.doc);
            Ultilities.replaceWord("<%RankName%>", chucDanh, Ultilities.doc);
            Ultilities.replaceWord("<%NoiSinh%>", noiSinh, Ultilities.doc);
            Ultilities.replaceWord("<%Phone%>", SDT , Ultilities.doc);
            Ultilities.replaceWord("<%Date%>", date, Ultilities.doc);
            Ultilities.Active();
        }

        private void viewDSTV_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            
        }

        private void viewDSTV_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (e.RowHandle > -1 && e.Column == colSTT)
                e.DisplayText = (e.RowHandle + 1).ToString();
        }

        private void btnIn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }
    }
}